import { getAddressList } from "@/util/util";
import adPicker from "@/components/adPicker";
import Validator from "@/util/validator";
export default {
  components: { adPicker },
  data() {
    return {
      form: {
        Name: "",
        Mobile: "",
        Code: "",
        Province: "",
        City: "",
        Area: "",
        Town: "",
        Address: "",
        CodeValue: "获取验证码",
        disabled: false,
      },
    };
  },
  methods: {
    /**
     * 获取验证码
     */
    getCode() {
      let validator = new Validator(this.form);
      validator.add("Mobile", [
        {
          strategy: "isMoblie",
          errorMsg: "请输入正确手机号码",
        },
      ]);
      let errorMsg = validator.start();
      if (errorMsg) {
        uni.showToast({
          title: errorMsg,
          icon: "none",
          duration: 4000,
        });
        return false;
      }
      let times = 60;
      this.form.disabled = true;
      let timer = setInterval(() => {
        times--;
        this.form.CodeValue = `${times}s`;

        if (times <= 0) {
          this.form.CodeValue = `重新获取`;
          this.form.disabled = false;
          clearInterval(timer);
        }
      }, 1000);
    },
    /**
     * 提交信息
     */
    postInfo() {
      let validator = new Validator(this.form);
      validator.add("Name", [
        {
          strategy: "isEmpty",
          errorMsg: "请输入姓名",
        },
      ]);
      validator.add("Mobile", [
        {
          strategy: "isMoblie",
          errorMsg: "请输入正确手机号码",
        },
      ]);
      validator.add("Code", [
        {
          strategy: "isVerification",
          errorMsg: "请输入正确的验证码",
        },
      ]);
      validator.add("Province", [
        {
          strategy: "isEmpty",
          errorMsg: "请选择省份",
        },
      ]);
      validator.add("City", [
        {
          strategy: "isEmpty",
          errorMsg: "请选择城市",
        },
      ]);
      validator.add("Area", [
        {
          strategy: "isEmpty",
          errorMsg: "请选择区或县",
        },
      ]);
      validator.add("Address", [
        {
          strategy: "isEmpty",
          errorMsg: "请输入具体地址",
        },
      ]);
      let errorMsg = validator.start();
      if (errorMsg) {
        uni.showToast({
          title: errorMsg,
          icon: "none",
          duration: 4000,
        });
        return false;
      }
      uni.showToast({
        title: "校验通过",
        icon: "none",
        duration: 4000,
      });
    },
    adCho(param) {
      switch (param.LevelNum) {
        case 1:
          this.form.Province = param.value;
          this.form.City = "";
          this.form.Area = "";
          this.form.Town = "";
          break;
        case 2:
          this.form.City = param.value;
          this.form.Area = "";
          this.form.Town = "";
          break;
        case 3:
          this.form.Area = param.value;
          this.form.Town = "";
          break;
        case 4:
          this.form.Town = param.value;
      }
    },
  },
  onLoad() {},
};